﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace INSTA.Exercices.Comparable
{
    public class Person : /*IComparable,*/ IComparable<Person>
    {
        public string Name      { get; set; }
        public int YearOfBirth  { get; set; }

        /// <summary>
        /// Implémentation de IComparable
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        //public int CompareTo(object obj)
        //{
        //    int result = 0;

        //    if (!(obj is Person))
        //    {
        //        throw new InvalidCastException();
        //    }
            
        //    // On recaste l'objet en Person..
        //    var personToCompare = obj as Person;

        //    result = this.Name.CompareTo(personToCompare.Name);
            

        //    return result;
        //}

        public int CompareTo(Person other)
        {
            return Name.CompareTo(other.Name);
        }
    }
}
